You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Regressed from #17467, which has SourceLink metadata read the git revision from the workspace status file on every build; this prevented RBE from being able to cache test results, and results in every single RBE run executing all .NET tests regardless of changes (~120 RBE executor minutes)
💥 What does this PR do?
Prevents dotnet assemblies and tests from being rebuilt and rerun on every CI job. The SourceLink metadata now embeds the git revision only when stamping, so unstamped builds are cacheable again.
🔧 Implementation Notes
csharp_sourcelink_library gains a stamp attribute that defaults to the --stamp flag through a config_setting, the same pattern rules_pkg uses. Release builds already pass --stamp, so published packages keep the real commit; everything else gets the existing HEAD fallback.
🤖 AI assistance
AI assisted (complete below)
Tool(s): Claude Code (Fable 5.1)
What was generated: the CI log analysis that identified the cache miss, the fix, and this description
I reviewed all AI output and can explain the change
• Gates SourceLink git revision embedding behind Bazel stamping.
• Uses HEAD metadata for unstamped builds, restoring remote cache reuse.
• Preserves exact commit links for stamped release artifacts.
Diagram
graph TD
A["Bazel Build"] --> B["Stamp Config"] --> C["SourceLink Rule"] --> D{"Stamped?"}
D -->|Yes| E["Git Revision"] --> G["SourceLink JSON"] --> H["C# Assemblies"]
D -->|No| F["HEAD Fallback"] --> G
Loading
High-Level Assessment
The selected approach is appropriate: it preserves revision-accurate SourceLink data for stamped releases while removing workspace-status dependencies from ordinary builds. A stable HEAD fallback retains SourceLink functionality without forcing assembly and test cache invalidation, and callers can still override the stamp attribute explicitly.
Files changed (2) +35 / -1
Bug fix (1) +29 / -1
sourcelink.bzlAvoid workspace revision inputs for unstamped SourceLink builds+29/-1
Avoid workspace revision inputs for unstamped SourceLink builds
• Adds a stamp attribute and macro that defaults to the global Bazel stamping flag. Unstamped builds write stable HEAD-based metadata directly, while stamped builds continue reading the exact revision from workspace status.
BUILD.bazelExpose Bazel stamping as a private .NET configuration target+6/-0
Expose Bazel stamping as a private .NET configuration target
• Adds a package-visible config setting that detects when Bazel stamping is enabled. The SourceLink macro uses this setting to derive its default stamp behavior.
1. Build caching can silently regress 📘 Rule violation☼ Reliability
Description
csharp_sourcelink_library now selects between HEAD metadata and workspace-status revision
metadata without a focused automated test. A later change to either stamping branch could make every
.NET assembly and test depend on the current revision again or omit the revision from published
metadata without detection.
+ if not ctx.attr.stamp:+ ctx.actions.write(+ output = output,+ content = '{{"documents":{{"*":"{repo}/raw/HEAD/*"}}}}\n'.format(
Evidence
Compliance rule 5 requires focused regression coverage for changed behavior. The cited
implementation introduces distinct stamped and unstamped metadata paths, but the PR adds no test
exercising either path.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
Add focused regression coverage for SourceLink metadata generation in stamped and unstamped builds.
## Issue Context
The unstamped path must generate a `HEAD` URL without reading workspace status, while the stamped path must embed the stable Git revision and retain its existing fallback behavior.
## Fix Focus Areas
- dotnet/private/sourcelink.bzl[13-30]
- dotnet/private/sourcelink.bzl[102-125]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Review mode: ⚖️ Balanced: This changes Bazel rule behavior and stamping/configuration semantics across .NET builds, so a careful review is warranted despite the localized diff.
Tip of the day
💡 Did you know, you can tweak Display preferences with a live preview to see your comment before it ships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
B-buildIncludes scripting, bazel and CI integrationsC-dotnet.NET Bindings
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issues
Regressed from #17467, which has SourceLink metadata read the git revision from the workspace status file on every build; this prevented RBE from being able to cache test results, and results in every single RBE run executing all .NET tests regardless of changes (~120 RBE executor minutes)
💥 What does this PR do?
Prevents dotnet assemblies and tests from being rebuilt and rerun on every CI job. The SourceLink metadata now embeds the git revision only when stamping, so unstamped builds are cacheable again.
🔧 Implementation Notes
csharp_sourcelink_librarygains astampattribute that defaults to the--stampflag through aconfig_setting, the same pattern rules_pkg uses. Release builds already pass--stamp, so published packages keep the real commit; everything else gets the existingHEADfallback.🤖 AI assistance
🔄 Types of changes